package com.card.manager.controller;

import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.card.framework.page.model.PageModel;
import com.card.framework.util.CommonUtil;
import com.card.manager.domain.Aaa;
import com.card.manager.domain.Aba;
import com.card.manager.services.AaaService;


@Controller
@RequestMapping("/aaa")
public class AaaController {
	final static Logger loger = Logger.getLogger(AaaController.class);
	@Autowired(required=true) 
	private AaaService aaaServices;
	@RequestMapping("/index")
	public String aaa(){
		return "aaaList";
	}
	
	@RequestMapping("/aaaAddWindow")
	public String aaaAddWindow() {
		return "aaaPopWindow";
	}
	@RequestMapping("/aaaUpdateWindow")
	public String aaaUpdateWindow() {
		return "aaaPopWindow";
	}
	@RequestMapping(value="/queryList",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> queryList(Aaa aaa,Aba aba,PageModel pageModel){
		return aaaServices.selectAaaForPage(aaa,aba,pageModel);
	}
	
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> delete(@RequestParam("json") String json){
		Map<String, String> map = new HashMap<String, String>();
		try {
			aaaServices.deleteAaas(CommonUtil.getBean(json, Aaa.class));
			map.put("mes", "删除成功");
		} catch (Throwable e) {
			CommonUtil.throwsException(map, e);
			loger.error("delete", e);
		}
		return map;//重定向
	}
	
//	@RequestMapping(value="/addOrUpdate",method=RequestMethod.POST)
//	@ResponseBody
//	public Map<String, String> addOrUpdate(Aaa aaa){
//		Map<String, String> map = new HashMap<String, String>();
//		try {
//			aaaServices.addOrUpdate(aaa);
//			map.put("mes", "操作成功");
//		}
//		catch (Throwable e) {
//			CommonUtil.throwsException(map, e);
//			loger.error("addOrUpdate", e);
//		}
//		return map; 
//	}
	
	@RequestMapping(value="/aaaAdd",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> aaaAdd(Aaa aaa){
		Map<String, String> map = new HashMap<String, String>();
		try {
			aaaServices.addOrUpdate(aaa);
			map.put("mes", "操作成功");
		}
		catch (Throwable e) {
			CommonUtil.throwsException(map, e);
			loger.error("addOrUpdate", e);
		}
		return map; 
	}
	
	@RequestMapping(value="/aaaUpdate",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, String> aaaUpdate(Aaa aaa){
		Map<String, String> map = new HashMap<String, String>();
		try {
			aaaServices.addOrUpdate(aaa);
			map.put("mes", "操作成功");
		}
		catch (Throwable e) {
			CommonUtil.throwsException(map, e);
			loger.error("addOrUpdate", e);
		}
		return map; 
	}
}